<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="用户标识(数字0：未插入)" prop="userId">
        <el-input v-model="dataForm.userId" placeholder="用户标识(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="短信标识(字符串空：未插入)" prop="smsFlag">
        <el-input v-model="dataForm.smsFlag" placeholder="短信标识(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="手机号(数字0：未插入)" prop="mobile">
        <el-input v-model="dataForm.mobile" placeholder="手机号(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="短信验证码(数字0：未插入)" prop="verifyCode">
        <el-input v-model="dataForm.verifyCode" placeholder="短信验证码(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="短信验证码有效期(数字0：未插入)" prop="verifyCodeValidate">
        <el-input v-model="dataForm.verifyCodeValidate" placeholder="短信验证码有效期(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="短信发送时间(数字0：未插入)" prop="sendUtc">
        <el-input v-model="dataForm.sendUtc" placeholder="短信发送时间(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="短信验证时间(数字0：未插入)" prop="verifyUtc">
        <el-input v-model="dataForm.verifyUtc" placeholder="短信验证时间(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="操作员(字符串空：未插入)" prop="operator">
        <el-input v-model="dataForm.operator" placeholder="操作员(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="创建即上传时间(数字0：未插入)" prop="createUtc">
        <el-input v-model="dataForm.createUtc" placeholder="创建即上传时间(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="修改即更新时间(数字0：未插入)" prop="modifyUtc">
        <el-input v-model="dataForm.modifyUtc" placeholder="修改即更新时间(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="是否删除(数字0：未插入，1.未删除,2：删除，)" prop="isDeleted">
        <el-input v-model="dataForm.isDeleted" placeholder="是否删除(数字0：未插入，1.未删除,2：删除，)"></el-input>
      </el-form-item>
      <el-form-item label="版本号(数字0：未插入)" prop="version">
        <el-input v-model="dataForm.version" placeholder="版本号(数字0：未插入)"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import API from '@/api'
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          userId: '',
          smsFlag: '',
          mobile: '',
          verifyCode: '',
          verifyCodeValidate: '',
          sendUtc: '',
          verifyUtc: '',
          operator: '',
          createUtc: '',
          modifyUtc: '',
          isDeleted: '',
          version: ''
        },
        dataRule: {
          userId: [
            { required: true, message: '用户标识(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          smsFlag: [
            { required: true, message: '短信标识(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          mobile: [
            { required: true, message: '手机号(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          verifyCode: [
            { required: true, message: '短信验证码(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          verifyCodeValidate: [
            { required: true, message: '短信验证码有效期(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          sendUtc: [
            { required: true, message: '短信发送时间(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          verifyUtc: [
            { required: true, message: '短信验证时间(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          operator: [
            { required: true, message: '操作员(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          createUtc: [
            { required: true, message: '创建即上传时间(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          modifyUtc: [
            { required: true, message: '修改即更新时间(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '是否删除(数字0：未插入，1.未删除,2：删除，)不能为空', trigger: 'blur' }
          ],
          version: [
            { required: true, message: '版本号(数字0：未插入)不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            API.upksmscode.info(this.dataForm.id).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.userId = data.upksmscode.userId
                this.dataForm.smsFlag = data.upksmscode.smsFlag
                this.dataForm.mobile = data.upksmscode.mobile
                this.dataForm.verifyCode = data.upksmscode.verifyCode
                this.dataForm.verifyCodeValidate = data.upksmscode.verifyCodeValidate
                this.dataForm.sendUtc = data.upksmscode.sendUtc
                this.dataForm.verifyUtc = data.upksmscode.verifyUtc
                this.dataForm.operator = data.upksmscode.operator
                this.dataForm.createUtc = data.upksmscode.createUtc
                this.dataForm.modifyUtc = data.upksmscode.modifyUtc
                this.dataForm.isDeleted = data.upksmscode.isDeleted
                this.dataForm.version = data.upksmscode.version
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            var params = {
              'id': this.dataForm.id || undefined,
              'userId': this.dataForm.userId,
              'smsFlag': this.dataForm.smsFlag,
              'mobile': this.dataForm.mobile,
              'verifyCode': this.dataForm.verifyCode,
              'verifyCodeValidate': this.dataForm.verifyCodeValidate,
              'sendUtc': this.dataForm.sendUtc,
              'verifyUtc': this.dataForm.verifyUtc,
              'operator': this.dataForm.operator,
              'createUtc': this.dataForm.createUtc,
              'modifyUtc': this.dataForm.modifyUtc,
              'isDeleted': this.dataForm.isDeleted,
              'version': this.dataForm.version
            }
            var tick = !this.dataForm.id ? API.upksmscode.add(params) : API.upksmscode.update(params)
            tick.then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
